package com.yanqu.road.entity.activity;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.union.UnionBaseInfo;

import java.math.BigInteger;
import java.util.*;


public class UnionActivityConditionData extends DataObject {
    private String unionUid;
    private UnionBaseInfo unionBaseInfo = new UnionBaseInfo();
    private int activityId;
    private int conditionType;
    private int conditionId;
    private BigInteger preValue = BigInteger.ZERO;
    private BigInteger value = BigInteger.ZERO;
    private boolean isGetReward;
    private long lastUpdateTime;
    private List<Long> memberUserIdList = new ArrayList<>();
    private String info;//存放不同活动对应需要的信息
    private Map<Long,Integer> memberPositionMap = new HashMap<>(); //商会活动时玩家职位信息
    private BigInteger extraValue = BigInteger.ZERO;

    public String getUnionUid() {
        return unionUid;
    }

    public void setUnionUid(String unionUid) {
        if(!Objects.equals(this.unionUid, unionUid)) {
            this.unionUid = unionUid;
            setUpdateOption();
        }
    }

    public UnionBaseInfo getUnionBaseInfo() {
        return unionBaseInfo;
    }

    public String getUnionBaseInfoJsonStr(){
        if(null == unionBaseInfo){
            return "{}";
        }else {
            return JSON.toJSONString(unionBaseInfo);
        }
    }

    public void setUnionBaseInfo(UnionBaseInfo unionBaseInfo) {
        this.unionBaseInfo = unionBaseInfo;
        setUpdateOption();
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if(this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public int getConditionId() {
        return conditionId;
    }

    public void setConditionId(int conditionId) {
        if(this.conditionId != conditionId) {
            this.conditionId = conditionId;
            setUpdateOption();
        }
    }

    public BigInteger getPreValue() {
        return preValue;
    }

    public void setPreValue(BigInteger preValue) {
        if(!Objects.equals(this.preValue, preValue)) {
            this.preValue = preValue;
            setUpdateOption();
        }
    }

    public BigInteger getValue() {
        return value;
    }

    public void setValue(BigInteger value) {
        if(!Objects.equals(this.value, value)) {
            this.value = value;
            setUpdateOption();
        }
    }

    public boolean isGetReward() {
        return isGetReward;
    }

    public void setGetReward(boolean getReward) {
        if(this.isGetReward != getReward) {
            isGetReward = getReward;
            setUpdateOption();
        }
    }

    public long getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(long lastUpdateTime) {
        if(this.lastUpdateTime != lastUpdateTime) {
            this.lastUpdateTime = lastUpdateTime;
            setUpdateOption();
        }
    }

    public List<Long> getMemberUserIdList() {
        return memberUserIdList;
    }

    public void setMemberUserIdList(List<Long> memberUserIdList) {
        this.memberUserIdList = memberUserIdList;
        setUpdateOption();
    }

    public boolean hasMemberUserId(long userId){
        return memberUserIdList.contains(userId);
    }

    public void addMemberUserId(long userId){
        if(!hasMemberUserId(userId)){
            memberUserIdList.add(userId);
            setUpdateOption();
        }
    }

    public void removeMemberUserId(long userId){
        if(hasMemberUserId(userId)){
            memberUserIdList.remove(userId);
            setUpdateOption();
        }
    }

    public int getMemberUserCount(){
        return memberUserIdList.size();
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        if(!info.equals(this.info)){
            this.info = info;
            setUpdateOption();
        }
    }
    public int getConditionType() {
        return conditionType;
    }

    public void setConditionType(int conditionType) {
        if (this.conditionType != conditionType) {
            this.conditionType = conditionType;
            setUpdateOption();
        }
    }

    public Map<Long, Integer> getMemberPositionMap() {
        return memberPositionMap;
    }

    public void setMemberPositionMap(Map<Long, Integer> memberPositionMap) {
        this.memberPositionMap = memberPositionMap;
        setUpdateOption();
    }

    public String getMemberPositionMapJsonStr(){
        if(null == memberPositionMap){
            return "{}";
        }else {
            return JSON.toJSONString(memberPositionMap);
        }
    }

    public void changeMemberPosition(long userId, int position){
        if (!memberPositionMap.containsKey(userId) ||
                (memberPositionMap.containsKey(userId) && memberPositionMap.get(userId) != position)) {
            this.memberPositionMap.put(userId, position);
            setUpdateOption();
        }
    }

    public void removeMemberPosition(long userId) {
        if (memberPositionMap.containsKey(userId)) {
            this.memberPositionMap.remove(userId);
            setUpdateOption();
        }
    }

    public void removeAllMemberUserId() {
        if (memberUserIdList != null) {
            memberUserIdList.clear();
            setUpdateOption();
        }
    }

    public void removeAllMemberPosition() {
        if (memberPositionMap != null) {
            memberPositionMap.clear();
            setUpdateOption();
        }
    }

    public BigInteger getExtraValue() {
        return extraValue;
    }

    public void setExtraValue(BigInteger extraValue) {
        if (!Objects.equals(this.extraValue, extraValue)) {
            this.extraValue = extraValue;
            setUpdateOption();
        }
    }
}
